package com.secondkill.dao;

import com.secondkill.entity.Goods;
import com.secondkill.entity.MiaoshaGoods;
import com.secondkill.vo.GoodsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by zhangkai12 on 2018/7/9.
 */
@Mapper
public interface GoodsMapper {

    @Insert("insert into goods (goods_name, goods_title, goods_img, goods_detail, goods_price, goods_stock) " +
            "values (#{goodsName}, #{goodsTitle}, #{goodsImg}, #{goodsDetail}, #{goodsPrice}, #{goodsStock})")
    public void insertGoods(Goods goods);

    @Select("select g.*, m.miaosha_price, m.stock_count, m.start_date, m.end_date from miaosha_goods m left join goods g on m.goods_id = g.id")
    public List<GoodsVo> listGoodsVo();

    @Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.miaosha_price from miaosha_goods mg " +
            "left join goods g on mg.goods_id = g.id where g.id = #{goodsId}")
    public GoodsVo getGoodsVoByGoodsId(long goodsId);


    // 减少库存
    @Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId}")
    public int reduceStock(MiaoshaGoods g);
}
